var t = require("../../../@babel/runtime/helpers/interopRequireDefault")(require("../../../utils/util.js")), a = getApp(), i = require("../../../mybehaviors/location/location");

Page({
    behaviors: [ i ],
    data: {
        categories: [ {
            id: 0,
            sort: 0,
            name: "全部",
            calssify_title: "全部"
        } ],
        cate: [],
        curr: 0,
        upNow: !1,
        listData: "",
        page: 1,
        inpText: "",
        search: !1
    },
    onLoad: function(t) {
        var a = this;
        if (console.log(t), this.setData({
            calssify_id: t.id,
            city: t.city,
            fenl: t.fenl
        }), t.fenl) {
            var i = "";
            "poper" == t.fenl ? (this.setData({
                is_discount: 1
            }), i = "人气精选") : "hot" == t.fenl ? (this.setData({
                is_hot: 1
            }), i = "近期热门") : i = "分类活动", wx.setNavigationBarTitle({
                title: i
            });
        }
        this.data.city || this._getLocation(function() {
            a.getList(a.data.calssify_id);
        }), this.getList(this.data.calssify_id), this.getFl();
    },
    goDw: function(t) {
        wx.navigateTo({
            url: "/packageC/o2o/o2oLocation/o2oLocation?tag=activitySort"
        });
    },
    insearchCurr: function(t) {
        var a = t.currentTarget.dataset.item.id, i = t.currentTarget.dataset.item.sort;
        this.setData({
            curr: i,
            upNow: !this.data.upNow,
            page: 1,
            calssify_id: a
        }), this.getList();
    },
    changeNow: function() {
        this.setData({
            upNow: !this.data.upNow,
            page: 1
        });
    },
    results: function(t) {
        var a = this;
        t.forEach(function(t, i) {
            a.data.calssify_id == t.id && a.setData({
                toView: "item".concat(i),
                curr: i
            });
        });
    },
    tapNav: function(t) {
        console.log(t), this.setData({
            calssify_id: t.currentTarget.dataset.kid,
            page: 1,
            curr: t.currentTarget.dataset.ind
        }), this.getList(t.currentTarget.dataset.kid);
    },
    goSearch: function(t) {
        wx.navigateTo({
            url: "/packageC/Myshaky/searchResult/searchResult?city_name=" + this.data.city + "&&keywords=" + this.data.inpText
        });
    },
    inpText: function(t) {
        this.setData({
            inpText: t.detail.value
        });
    },
    goxq: function(t) {
        var a = t.currentTarget.id;
        wx.navigateTo({
            url: "/packageC/Myshaky/enrollEnter/enrollEnter?id=" + a
        });
    },
    onReady: function() {},
    onShow: function() {
        var t = this;
        this._getLocation(function(a) {
            console.log(a, "ssssss"), t.getList(t.data.calssify_id);
        });
    },
    onHide: function() {},
    onUnload: function() {},
    onPullDownRefresh: function() {},
    onReachBottom: function() {
        console.log(1111), this.data.current_page < this.data.last_page && (this.setData({
            page: this.data.page + 1
        }), wx.showLoading({
            title: "加载中",
            mask: !0
        }), this.getMoreList());
    },
    onShareAppMessage: function() {},
    getList: function(i) {
        var e = this, s = {}, n = "";
        "Channel" == this.data.fenl ? (n = a.getNetAddresss("plugin.activity-apply.api.index.getAll"), 
        s = {
            calssify_id: this.data.calssify_id,
            page: e.data.page,
            city_name: e.data.city ? e.data.city : ""
        }) : (n = a.getNetAddresss("plugin.activity-apply.api.index.getCount"), s = e.data.is_discount ? {
            calssify_id: this.data.calssify_id,
            city_name: e.data.city ? e.data.city : "",
            is_discount: e.data.is_discount ? e.data.is_discount : ""
        } : {
            calssify_id: this.data.calssify_id,
            city_name: e.data.city ? e.data.city : "",
            is_hot: e.data.is_hot ? e.data.is_hot : ""
        }), console.log(s), a._getNetWork({
            url: n,
            data: s,
            success: function(a) {
                var i = a.data;
                if (1 == i.result) {
                    console.log(i);
                    for (var s = 0; s < i.data.data.length; s++) i.data.data[s].start_time = t.default.formatTimeTwo(i.data.data[s].start_time, "Y/M/D h:m:s");
                    var n = Date.parse(new Date()) / 1e3;
                    e.setData({
                        listData: i.data.data,
                        current_page: i.data.current_page,
                        last_page: i.data.last_page,
                        nowTime: n
                    });
                }
            },
            fail: function(t) {
                console.log(t);
            }
        });
    },
    getFl: function() {
        var t = a.getNetAddresss("plugin.activity-apply.api.index.getCalssify"), i = this;
        a._getNetWork({
            url: t,
            success: function(t) {
                var a = t.data;
                if (1 == a.result) {
                    console.log(a.data);
                    var e = a.data.reverse(), s = i.data.categories.concat(e);
                    console.log(s), i.setData({
                        categories: s,
                        cate: a.data,
                        len: a.data.length
                    }, i.results(s));
                }
            },
            fail: function(t) {
                console.log(t);
            }
        });
    },
    getMoreList: function() {
        var i = this, e = {}, s = "";
        "Channel" == i.data.fenl ? (s = a.getNetAddresss("plugin.activity-apply.api.index.getAll"), 
        e = {
            calssify_id: i.data.calssify_id,
            page: i.data.page,
            city_name: i.data.city ? i.data.city : ""
        }) : (s = a.getNetAddresss("plugin.activity-apply.api.index.getCount"), e = i.data.is_discount ? {
            calssify_id: i.data.calssify_id,
            city: i.data.city,
            is_discount: i.data.is_discount ? i.data.is_discount : ""
        } : {
            calssify_id: i.data.calssify_id,
            city: i.data.city,
            is_hot: i.data.is_hot ? i.data.is_hot : ""
        }), console.log(e), a._getNetWork({
            url: s,
            data: e,
            success: function(a) {
                var e = a.data;
                if (1 == e.result) {
                    console.log(e);
                    for (var s = 0; s < e.data.data.length; s++) e.data.data[s].start_time = t.default.formatTimeTwo(e.data.data[s].start_time, "Y/M/D h:m:s");
                    var n = Date.parse(new Date()) / 1e3;
                    if (e.data.current_page > e.data.last_page) return wx.hideLoading(), wx.showToast({
                        title: "没有更多",
                        icon: "none"
                    }), void i.setData({
                        current_page: e.data.current_page,
                        last_page: e.data.last_page
                    });
                    wx.hideLoading(), i.setData({
                        listData: i.data.listData.concat(e.data.data),
                        current_page: e.data.current_page,
                        last_page: e.data.last_page,
                        nowTime: n
                    });
                }
            },
            fail: function(t) {
                console.log(t);
            }
        });
    }
});